﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for reviewDAL
/// </summary>
public class reviewDAL
{
    DataAccess da = new DataAccess();

	public reviewDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public DataTable getReviews()
    {
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = da.AddParameter("review_id", DBNull.Value, SqlDbType.Int);
        return da.executeSelect("SELECT_REVIEW", paramList);
    }
    public DataTable getReviewByReviewID(int review_id){
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = da.AddParameter("review_id", review_id, SqlDbType.Int);
        return da.executeSelect("SELECT_REVIEW", paramList);
    }

    public int insertReview(review re){
        SqlParameter[] paramList = new SqlParameter[6];
        paramList[0] = da.AddParameter("review_id",DBNull.Value, SqlDbType.Int);
        paramList[1] = da.AddParameter("product_id", re.Product_id, SqlDbType.Int);
        paramList[2] = da.AddParameter("customer_id", re.Customer_id, SqlDbType.Int);
        paramList[3] = da.AddParameter("subject", re.Subject, SqlDbType.NVarChar, 30);
        paramList[4] = da.AddParameter("comment", re.Comment, SqlDbType.NVarChar, 100);
        paramList[5] = da.AddParameter("status", re.Status, SqlDbType.Bit);
        return da.executeUpdate("INSERT_REVIEW", paramList);
    }

    public int updateReview(review re){
        SqlParameter[] paramList = new SqlParameter[7];
        paramList[0] = da.AddParameter("review_id",re.Review_id , SqlDbType.Int);
        paramList[1] = da.AddParameter("product_id", re.Product_id, SqlDbType.Int);
        paramList[2] = da.AddParameter("customer_id", re.Customer_id, SqlDbType.Int);
        paramList[3] = da.AddParameter("subject", re.Subject, SqlDbType.NVarChar, 30);
        paramList[4] = da.AddParameter("comment", re.Comment, SqlDbType.NVarChar, 100);
        paramList[5] = da.AddParameter("status", re.Status, SqlDbType.Bit);
        paramList[6] = da.AddParameter("date_modified", DBNull.Value, SqlDbType.DateTime);
        return da.executeUpdate("INSERT_REVIEW", paramList);
    }

    public DataTable getReviewsByStatus(bool status){
        SqlParameter[] paramList = new SqlParameter[2];
        paramList[0] = da.AddParameter("review_id", DBNull.Value, SqlDbType.Int);
        paramList[1] = da.AddParameter("status", status, SqlDbType.Bit);
        return da.executeSelect("SELECT_REVIEW", paramList);
    }
    public int delete_review(int review_id) 
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = da.AddParameter("review_id", review_id, SqlDbType.Int);
        return da.executeUpdate("INSERT_REVIEW", paraList);
    }
}
